const webpack = require("webpack");
var os = require('os'), ip = '', ifaces = os.networkInterfaces() // 获取本机ip
out:
for (var i in ifaces) {
  for (var j in ifaces[i]) {
    var val = ifaces[i][j]
    if (val.family === 'IPv4' && val.address !== '127.0.0.1') {
      console.log(val)
      ip = val.address
      break out
    }
  }
}
module.exports = {
  configureWebpack: {
    devtool: "source-map",
    plugins: [
      new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "window.jQuery": "jquery",
        "window.$": "jquery",
        Popper: ["popper.js", "default"]
      })
    ]
  },
  publicPath: "./",
  //outputDir:'dist'    //构建输出目录
  assetsDir: 'assets',    //静态资源目录
  lintOnSave: false,      //是否开启eslint保存检测，有效值：true || false || 'error'开启后语法要求很严谨
  chainWebpack: config => {
    config.plugin('define').tap(definitions => {
      const urlIp = {
        url: "http://61.240.138.156:350/auth",
        realm: "pae",
        clientId: "pae"
      }
      Object.assign(definitions[0]['process.env'], {
        API_ROOT: `'${process.env.API_ROOT}'`,
        KEYCLOAK_CONF: `${urlIp}`,
      });
      return definitions;
    });
  },
  devServer: {
    open: false,         //启动项目是否自动打开主页
    host: "0.0.0.0",   //项目访问地址  localhost
    port: 8096,          //端口号
    https: false,       //https协议
    hotOnly: false,     //热更新
    proxy: {
      '/rest': {
        // target: ' http://61.240.138.156:350/rest',
        target: ' http://61.240.138.156:8091/rest',
        changeOrigin: true,
        pathRewrite: {
          '^/rest': ''
        }
      }

    }
  }
};


switch (process.env.VUE_APP_CURENV) {
  case 'development':
    console.log('当前运行环境为：开发环境')
    break;
  case 'test':
    console.log('当前运行环境为：测试环境')
    break;
  case 'production':
    console.log(ip)
    console.log('当前运行环境为：生产环境')
    break;
  default:
    console.log('当前运行环境为：', process.env.VUE_APP_CURENV)
}